package me.kagami.exex.registry;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;

public class CellStyleService {

	public List<CellStyle> initCellStyleList(Sheet sheet) {
		List<CellStyle> cellStyleList = new ArrayList<>();
		Row headRow = sheet.getRow(0);
		if (headRow != null) {
			short firstCellNum = headRow.getFirstCellNum();
			short lastCellNum = headRow.getLastCellNum();
			for (short i = firstCellNum; i < lastCellNum; i++) {
				cellStyleList.add(headRow.getCell(i).getCellStyle());
			}
		}
		return cellStyleList;
	}

	public static void assignCellStyle(Cell cell, int cellIndex, List<CellStyle> cellStyleList) {
		if (cellStyleList.size() < cellIndex) {
			return;
		}
		CellStyle style = cellStyleList.get(cellIndex);
		if (Objects.isNull(style)) {
			return;
		}
		cell.setCellStyle(style);
	}

}
